package com.liangzhong.model.youngTrain.vo
{
	import com.liangzhong.model.BuildingBaseInfoVo;
	/**
	 *青训营信息vo 
	 * @author lake
	 * 
	 */	
	public class YoungTrainInfoVo extends BuildingBaseInfoVo
	{
		/**
		 *系统默认球童数量 
		 */		
		public var caddienum 			:int;
		/**
		 * 点券开的球童数量
		 */		
		public var numcashpoint 		:int;
		/**
		 * 每天产生球童次数
		 */		
		public var caddiecount 			:int;
		/**
		 *一天已产生的球童次数 
		 */		
		public var 	caddie				:int;
		/**
		 *球童列表 
		 * {index:1,pid:1,growbegin:10000,grow:200}
		 * 索引(数据库表位置) 球员包ID 开始成长时间 成长时间
		 */		
		public var playerChildList		:Array = [];
		
		public function YoungTrainInfoVo()
		{
			super();
		}
		/**
		 *解析信息 
		 * @param data
		 * 
		 */		
		override public function parseBaseInfo(data:Object):void
		{
			for (var str:String in data)
			{
				if(this.hasOwnProperty(str))
				{
					this[str] = data[str];
				}
			}
			playerChildList = [];
			var pid :int;
			var pcInfo :PlayerChildInfoVo;
			for(var i :int = 1;i <= 12;i++)
			{
				pid = data["pid" + i];
				if(pid != 0)
				{
					pcInfo = new PlayerChildInfoVo();
					pcInfo.pid 			= pid;
					pcInfo.index 		= i;
					pcInfo.growbegin 	= data["growbegin" + i];
					pcInfo.grow 		= data["grow" + i];
					playerChildList.push(pcInfo);
				}
			}
			//test
			/*var pcInfo :PlayerChildInfoVo;
			var pids :Array = [10,24,25,26,27,28,25,27,28,10,24,27];
			for(var i :int = 1; i <= 6;i++)
			{
				pcInfo = new PlayerChildInfoVo();
				pcInfo.growbegin = new Date().time / 1000;
				pcInfo.grow = i * 100;
				pcInfo.index = i;
				pcInfo.pid = pids[i - 1];
				playerChildList.push(pcInfo);
			}*/
		}
		/**
		 *根据索引获取球童信息 
		 * @param index
		 * @return 
		 * 
		 */		
		private function getChildInfoByIndex(index :int):Object
		{
			for each(var obj :Object in playerChildList)
			{
				if(obj.index == index)
				{
					return obj;
				}
			}
			return null;
		}
		/**
		 *添加球童 
		 * @param obj
		 * 
		 */		
		public function addPlayerChild(obj :Object):void
		{
			var objC :Object = getChildInfoByIndex(obj.index);
			if(objC)
			{
				objC.pid 		= obj.pid ;
				objC.growbegin 	= obj.growbegin;
				objC.grow 		= obj.grow;
			}
			else
			{
				playerChildList.push(obj);
			}
		}
		/**
		 *获取成熟球童index 
		 * @return 
		 * 
		 */		
		public function getGrowCompleteIndexs():Array
		{
			var res :Array = [];
			for each(var pcinfo :PlayerChildInfoVo in playerChildList)
			{
				if(pcinfo.isGrowComplete)
				{
					res.push(pcinfo.index);
				}
			}
			return res;
		}
		/**
		 *设置球员完成状态（快速完成） 
		 * @param index
		 * 
		 */		
		public function setPlayerChildComplete(index :int):void
		{
			for each(var pcinfo :PlayerChildInfoVo in playerChildList)
			{
				if(pcinfo.index == index)
				{
					pcinfo.grow = 0;
				}
			}
		}
	}
}